package controller;

import gui.catalogues.products.ProductFormEvent;

import java.io.File;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

import model.Product;
import model.ProductDAO;

public class ProductController {
	// DummyDB db = new DummyDB();
	ProductDAO db = new ProductDAO();

	public List<Product> getProductList() {
		return db.getElementsList();
	}

	public void addProduct(ProductFormEvent e) {
		/*
		 * tp.tpAppend("name = " + e.getName() + ", surname = " + e.getSurname()
		 * + ", isIndirectClient? " + e.isChkIndirectClient() +
		 * ", ItCollateralClient id = " + e.getItCollateralClient().getId() +
		 * ", ItCollateralClient desc = " + e.getItCollateralClient() + "\n");
		 */

		/*CollateralClient cc;
		switch (e.getItCollateralClient().getId()) {
		case 0:
			cc = CollateralClient.noCollateral;
			break;
		case 1:
			cc = CollateralClient.alejandroAlcaide;
			break;
		case 2:
			cc = CollateralClient.juanPerez;
			break;
		case 3:
			cc = CollateralClient.pedroPerez;
			break;
		default:
			cc = CollateralClient.noCollateral;
			;
		}*/

		/*
		 * 
		 * */
		Product element = new Product(e.getProductDescription());

		db.addElement(element);
	}

	public void removeProduct(int index) {
		db.removeElement(index);
	}

	public void cSaveToFile(File file) throws IOException {
		db.saveToFile(file);
	}

	public void cLoadFromFile(File file) throws IOException,
			ClassNotFoundException {
		db.loadFromFile(file);
	}
	
	public void cConnectToDB() throws SQLException {
		db.h2Connect();
	}

	public void cSaveToDB() throws SQLException {
		db.saveToDB();
	}

	public void cLoadFromDB() throws SQLException {
		db.loadFromDB();
	}

	public void cDisconnectFromDB() throws SQLException {
		db.disconnect();
	}
}
